{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "36836780",
   "metadata": {},
   "outputs": [],
   "source": [
    "# pip install tqdm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a5c6449f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入相关库\n",
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import time\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "from subprocess import check_output\n",
    "import lightgbm as lgb\n",
    "import matplotlib.pyplot as plt\n",
    "from tqdm import tqdm_notebook as tqdm\n",
    "from sklearn.preprocessing import MinMaxScaler\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import confusion_matrix, log_loss\n",
    "from xgboost import XGBClassifier\n",
    "from lightgbm import LGBMClassifier\n",
    "from sklearn.pipeline import Pipeline\n",
    "from sklearn.model_selection import cross_validate\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9d948484",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>Elevation</th>\n",
       "      <th>Aspect</th>\n",
       "      <th>Slope</th>\n",
       "      <th>Horizontal_Distance_To_Hydrology</th>\n",
       "      <th>Vertical_Distance_To_Hydrology</th>\n",
       "      <th>Horizontal_Distance_To_Roadways</th>\n",
       "      <th>Hillshade_9am</th>\n",
       "      <th>Hillshade_Noon</th>\n",
       "      <th>Hillshade_3pm</th>\n",
       "      <th>...</th>\n",
       "      <th>Soil_Type32</th>\n",
       "      <th>Soil_Type33</th>\n",
       "      <th>Soil_Type34</th>\n",
       "      <th>Soil_Type35</th>\n",
       "      <th>Soil_Type36</th>\n",
       "      <th>Soil_Type37</th>\n",
       "      <th>Soil_Type38</th>\n",
       "      <th>Soil_Type39</th>\n",
       "      <th>Soil_Type40</th>\n",
       "      <th>Cover_Type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>11997</th>\n",
       "      <td>11998</td>\n",
       "      <td>2771</td>\n",
       "      <td>59</td>\n",
       "      <td>15</td>\n",
       "      <td>256</td>\n",
       "      <td>137</td>\n",
       "      <td>258</td>\n",
       "      <td>230</td>\n",
       "      <td>207</td>\n",
       "      <td>105</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14308</th>\n",
       "      <td>14309</td>\n",
       "      <td>3382</td>\n",
       "      <td>342</td>\n",
       "      <td>13</td>\n",
       "      <td>108</td>\n",
       "      <td>6</td>\n",
       "      <td>2534</td>\n",
       "      <td>193</td>\n",
       "      <td>221</td>\n",
       "      <td>166</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5169</th>\n",
       "      <td>5170</td>\n",
       "      <td>2319</td>\n",
       "      <td>114</td>\n",
       "      <td>23</td>\n",
       "      <td>90</td>\n",
       "      <td>32</td>\n",
       "      <td>458</td>\n",
       "      <td>252</td>\n",
       "      <td>209</td>\n",
       "      <td>71</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3326</th>\n",
       "      <td>3327</td>\n",
       "      <td>2331</td>\n",
       "      <td>135</td>\n",
       "      <td>1</td>\n",
       "      <td>424</td>\n",
       "      <td>37</td>\n",
       "      <td>1333</td>\n",
       "      <td>221</td>\n",
       "      <td>238</td>\n",
       "      <td>153</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12168</th>\n",
       "      <td>12169</td>\n",
       "      <td>2882</td>\n",
       "      <td>276</td>\n",
       "      <td>9</td>\n",
       "      <td>85</td>\n",
       "      <td>-1</td>\n",
       "      <td>2148</td>\n",
       "      <td>197</td>\n",
       "      <td>242</td>\n",
       "      <td>184</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 56 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          Id  Elevation  Aspect  Slope  Horizontal_Distance_To_Hydrology  \\\n",
       "11997  11998       2771      59     15                               256   \n",
       "14308  14309       3382     342     13                               108   \n",
       "5169    5170       2319     114     23                                90   \n",
       "3326    3327       2331     135      1                               424   \n",
       "12168  12169       2882     276      9                                85   \n",
       "\n",
       "       Vertical_Distance_To_Hydrology  Horizontal_Distance_To_Roadways  \\\n",
       "11997                             137                              258   \n",
       "14308                               6                             2534   \n",
       "5169                               32                              458   \n",
       "3326                               37                             1333   \n",
       "12168                              -1                             2148   \n",
       "\n",
       "       Hillshade_9am  Hillshade_Noon  Hillshade_3pm  ...  Soil_Type32  \\\n",
       "11997            230             207            105  ...            0   \n",
       "14308            193             221            166  ...            0   \n",
       "5169             252             209             71  ...            0   \n",
       "3326             221             238            153  ...            0   \n",
       "12168            197             242            184  ...            0   \n",
       "\n",
       "       Soil_Type33  Soil_Type34  Soil_Type35  Soil_Type36  Soil_Type37  \\\n",
       "11997            0            0            0            0            0   \n",
       "14308            0            0            0            0            0   \n",
       "5169             0            0            0            0            0   \n",
       "3326             0            0            0            0            0   \n",
       "12168            0            0            0            0            0   \n",
       "\n",
       "       Soil_Type38  Soil_Type39  Soil_Type40  Cover_Type  \n",
       "11997            0            0            0           5  \n",
       "14308            1            0            0           7  \n",
       "5169             0            0            0           3  \n",
       "3326             0            0            0           4  \n",
       "12168            0            0            0           5  \n",
       "\n",
       "[5 rows x 56 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#读取数据、\n",
    "df_forest = pd.read_csv('./data/train_forest_covertype.csv')\n",
    "#随机采样15120条数据\n",
    "df_forest = df_forest.sample(n=15120)\n",
    "n=15120\n",
    "df_forest_sample = df_forest.sample(n)\n",
    "df_forest_sample.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "0c53cb41",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>Elevation</th>\n",
       "      <th>Aspect</th>\n",
       "      <th>Slope</th>\n",
       "      <th>Horizontal_Distance_To_Hydrology</th>\n",
       "      <th>Vertical_Distance_To_Hydrology</th>\n",
       "      <th>Horizontal_Distance_To_Roadways</th>\n",
       "      <th>Hillshade_9am</th>\n",
       "      <th>Hillshade_Noon</th>\n",
       "      <th>Hillshade_3pm</th>\n",
       "      <th>...</th>\n",
       "      <th>Soil_Type32</th>\n",
       "      <th>Soil_Type33</th>\n",
       "      <th>Soil_Type34</th>\n",
       "      <th>Soil_Type35</th>\n",
       "      <th>Soil_Type36</th>\n",
       "      <th>Soil_Type37</th>\n",
       "      <th>Soil_Type38</th>\n",
       "      <th>Soil_Type39</th>\n",
       "      <th>Soil_Type40</th>\n",
       "      <th>Cover_Type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>15120.00000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "      <td>15120.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>7560.50000</td>\n",
       "      <td>2749.322553</td>\n",
       "      <td>156.676653</td>\n",
       "      <td>16.501587</td>\n",
       "      <td>227.195701</td>\n",
       "      <td>51.076521</td>\n",
       "      <td>1714.023214</td>\n",
       "      <td>212.704299</td>\n",
       "      <td>218.965608</td>\n",
       "      <td>135.091997</td>\n",
       "      <td>...</td>\n",
       "      <td>0.045635</td>\n",
       "      <td>0.040741</td>\n",
       "      <td>0.001455</td>\n",
       "      <td>0.006746</td>\n",
       "      <td>0.000661</td>\n",
       "      <td>0.002249</td>\n",
       "      <td>0.048148</td>\n",
       "      <td>0.043452</td>\n",
       "      <td>0.030357</td>\n",
       "      <td>4.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>4364.91237</td>\n",
       "      <td>417.678187</td>\n",
       "      <td>110.085801</td>\n",
       "      <td>8.453927</td>\n",
       "      <td>210.075296</td>\n",
       "      <td>61.239406</td>\n",
       "      <td>1325.066358</td>\n",
       "      <td>30.561287</td>\n",
       "      <td>22.801966</td>\n",
       "      <td>45.895189</td>\n",
       "      <td>...</td>\n",
       "      <td>0.208699</td>\n",
       "      <td>0.197696</td>\n",
       "      <td>0.038118</td>\n",
       "      <td>0.081859</td>\n",
       "      <td>0.025710</td>\n",
       "      <td>0.047368</td>\n",
       "      <td>0.214086</td>\n",
       "      <td>0.203880</td>\n",
       "      <td>0.171574</td>\n",
       "      <td>2.000066</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1.00000</td>\n",
       "      <td>1863.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-146.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>99.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>3780.75000</td>\n",
       "      <td>2376.000000</td>\n",
       "      <td>65.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>67.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>764.000000</td>\n",
       "      <td>196.000000</td>\n",
       "      <td>207.000000</td>\n",
       "      <td>106.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>7560.50000</td>\n",
       "      <td>2752.000000</td>\n",
       "      <td>126.000000</td>\n",
       "      <td>15.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>32.000000</td>\n",
       "      <td>1316.000000</td>\n",
       "      <td>220.000000</td>\n",
       "      <td>223.000000</td>\n",
       "      <td>138.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>4.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>11340.25000</td>\n",
       "      <td>3104.000000</td>\n",
       "      <td>261.000000</td>\n",
       "      <td>22.000000</td>\n",
       "      <td>330.000000</td>\n",
       "      <td>79.000000</td>\n",
       "      <td>2270.000000</td>\n",
       "      <td>235.000000</td>\n",
       "      <td>235.000000</td>\n",
       "      <td>167.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>6.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>15120.00000</td>\n",
       "      <td>3849.000000</td>\n",
       "      <td>360.000000</td>\n",
       "      <td>52.000000</td>\n",
       "      <td>1343.000000</td>\n",
       "      <td>554.000000</td>\n",
       "      <td>6890.000000</td>\n",
       "      <td>254.000000</td>\n",
       "      <td>254.000000</td>\n",
       "      <td>248.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>7.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8 rows × 56 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                Id     Elevation        Aspect         Slope  \\\n",
       "count  15120.00000  15120.000000  15120.000000  15120.000000   \n",
       "mean    7560.50000   2749.322553    156.676653     16.501587   \n",
       "std     4364.91237    417.678187    110.085801      8.453927   \n",
       "min        1.00000   1863.000000      0.000000      0.000000   \n",
       "25%     3780.75000   2376.000000     65.000000     10.000000   \n",
       "50%     7560.50000   2752.000000    126.000000     15.000000   \n",
       "75%    11340.25000   3104.000000    261.000000     22.000000   \n",
       "max    15120.00000   3849.000000    360.000000     52.000000   \n",
       "\n",
       "       Horizontal_Distance_To_Hydrology  Vertical_Distance_To_Hydrology  \\\n",
       "count                      15120.000000                    15120.000000   \n",
       "mean                         227.195701                       51.076521   \n",
       "std                          210.075296                       61.239406   \n",
       "min                            0.000000                     -146.000000   \n",
       "25%                           67.000000                        5.000000   \n",
       "50%                          180.000000                       32.000000   \n",
       "75%                          330.000000                       79.000000   \n",
       "max                         1343.000000                      554.000000   \n",
       "\n",
       "       Horizontal_Distance_To_Roadways  Hillshade_9am  Hillshade_Noon  \\\n",
       "count                     15120.000000   15120.000000    15120.000000   \n",
       "mean                       1714.023214     212.704299      218.965608   \n",
       "std                        1325.066358      30.561287       22.801966   \n",
       "min                           0.000000       0.000000       99.000000   \n",
       "25%                         764.000000     196.000000      207.000000   \n",
       "50%                        1316.000000     220.000000      223.000000   \n",
       "75%                        2270.000000     235.000000      235.000000   \n",
       "max                        6890.000000     254.000000      254.000000   \n",
       "\n",
       "       Hillshade_3pm  ...   Soil_Type32   Soil_Type33   Soil_Type34  \\\n",
       "count   15120.000000  ...  15120.000000  15120.000000  15120.000000   \n",
       "mean      135.091997  ...      0.045635      0.040741      0.001455   \n",
       "std        45.895189  ...      0.208699      0.197696      0.038118   \n",
       "min         0.000000  ...      0.000000      0.000000      0.000000   \n",
       "25%       106.000000  ...      0.000000      0.000000      0.000000   \n",
       "50%       138.000000  ...      0.000000      0.000000      0.000000   \n",
       "75%       167.000000  ...      0.000000      0.000000      0.000000   \n",
       "max       248.000000  ...      1.000000      1.000000      1.000000   \n",
       "\n",
       "        Soil_Type35   Soil_Type36   Soil_Type37   Soil_Type38   Soil_Type39  \\\n",
       "count  15120.000000  15120.000000  15120.000000  15120.000000  15120.000000   \n",
       "mean       0.006746      0.000661      0.002249      0.048148      0.043452   \n",
       "std        0.081859      0.025710      0.047368      0.214086      0.203880   \n",
       "min        0.000000      0.000000      0.000000      0.000000      0.000000   \n",
       "25%        0.000000      0.000000      0.000000      0.000000      0.000000   \n",
       "50%        0.000000      0.000000      0.000000      0.000000      0.000000   \n",
       "75%        0.000000      0.000000      0.000000      0.000000      0.000000   \n",
       "max        1.000000      1.000000      1.000000      1.000000      1.000000   \n",
       "\n",
       "        Soil_Type40    Cover_Type  \n",
       "count  15120.000000  15120.000000  \n",
       "mean       0.030357      4.000000  \n",
       "std        0.171574      2.000066  \n",
       "min        0.000000      1.000000  \n",
       "25%        0.000000      2.000000  \n",
       "50%        0.000000      4.000000  \n",
       "75%        0.000000      6.000000  \n",
       "max        1.000000      7.000000  \n",
       "\n",
       "[8 rows x 56 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看抽样数据\n",
    "df_forest_sample.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9905a0f2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(15120, 54)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#删除列 Soil_Type7 和 Soil_Tpel5\n",
    "df_forest_sample.drop(['Soil_Type7','Soil_Type15'],inplace=True,axis=1)\n",
    "\n",
    "df_forest_sample.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6a88f1a9",
   "metadata": {},
   "outputs": [],
   "source": [
    "XGB = XGBClassifier()\n",
    "lgbm = LGBMClassifier()\n",
    "#存储模型\n",
    "first_models = [XGB,lgbm]\n",
    "# 模型名字\n",
    "first_model_names = ['XGB','lgbm']\n",
    "seed=42 \n",
    "skf =5"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d800758e",
   "metadata": {},
   "source": [
    "1.ShuffleSplit 函数对数据进行切分，指定参数splitting_iterations 为 skf,test_size为0.3,train_size为0.6,random_state为seed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b40e9a82",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import ShuffleSplit\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "# Defining other steps\n",
    "n_folds = 5\n",
    "# 此行由考生填写\n",
    "skf = ShuffleSplit(n_splits=n_folds,test_size=0.3,train_size=0.6,random_state=seed)\n",
    "# 此行由考生填写\n",
    "std_sca = StandardScaler()\n",
    "X= df_forest_sample.drop(['Cover_Type'],axis=1)\n",
    "y= pd.factorize(df_forest_sample['Cover_Type'])[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f321af36",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MLA Name</th>\n",
       "      <th>MLA Parameters</th>\n",
       "      <th>MLA Train Accuracy Mean</th>\n",
       "      <th>MLA Test Accuracy Mean</th>\n",
       "      <th>MLA Time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [MLA Name, MLA Parameters, MLA Train Accuracy Mean, MLA Test Accuracy Mean, MLA Time]\n",
       "Index: []"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MLA_columns = ['MLA Name', 'MLA Parameters','MLA Train Accuracy Mean', 'MLA Test Accuracy Mean', 'MLA Time']\n",
    "MLA_compare = pd.DataFrame(columns = MLA_columns)\n",
    "#create table to compare MLA predictions\n",
    "MLA_predict = df_forest_sample[['Id']]\n",
    "train_size = X.shape[0]\n",
    "n_models = len(first_models)\n",
    "oof_pred =np.zeros((train_size,n_models))\n",
    "scores = []\n",
    "row_index=0\n",
    "MLA_compare"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "461ee113",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>11997</th>\n",
       "      <td>11998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14308</th>\n",
       "      <td>14309</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5169</th>\n",
       "      <td>5170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3326</th>\n",
       "      <td>3327</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12168</th>\n",
       "      <td>12169</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4115</th>\n",
       "      <td>4116</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7647</th>\n",
       "      <td>7648</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10885</th>\n",
       "      <td>10886</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9247</th>\n",
       "      <td>9248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13225</th>\n",
       "      <td>13226</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>15120 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          Id\n",
       "11997  11998\n",
       "14308  14309\n",
       "5169    5170\n",
       "3326    3327\n",
       "12168  12169\n",
       "...      ...\n",
       "4115    4116\n",
       "7647    7648\n",
       "10885  10886\n",
       "9247    9248\n",
       "13225  13226\n",
       "\n",
       "[15120 rows x 1 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MLA_predict"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ea497fe0",
   "metadata": {},
   "source": [
    "2.使用Pipeline进行模型训练set中指定标准为为('Scaler',std_sca)，模型为('Estimator',model) \n",
    "3.使用cross_validate函数对模型进行评分，模型使用model，数据集使用X，y,指定return_train_score为True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f535759f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[LightGBM] [Info] Auto-choosing col-wise multi-threading, the overhead of testing was 0.000525 seconds.\n",
      "You can set `force_col_wise=true` to remove the overhead.\n",
      "[LightGBM] [Info] Total Bins 2413\n",
      "[LightGBM] [Info] Number of data points in the train set: 12096, number of used features: 44\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Auto-choosing col-wise multi-threading, the overhead of testing was 0.000613 seconds.\n",
      "You can set `force_col_wise=true` to remove the overhead.\n",
      "[LightGBM] [Info] Total Bins 2411\n",
      "[LightGBM] [Info] Number of data points in the train set: 12096, number of used features: 45\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Auto-choosing col-wise multi-threading, the overhead of testing was 0.000529 seconds.\n",
      "You can set `force_col_wise=true` to remove the overhead.\n",
      "[LightGBM] [Info] Total Bins 2411\n",
      "[LightGBM] [Info] Number of data points in the train set: 12096, number of used features: 45\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Auto-choosing col-wise multi-threading, the overhead of testing was 0.000608 seconds.\n",
      "You can set `force_col_wise=true` to remove the overhead.\n",
      "[LightGBM] [Info] Total Bins 2413\n",
      "[LightGBM] [Info] Number of data points in the train set: 12096, number of used features: 45\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Auto-choosing col-wise multi-threading, the overhead of testing was 0.000821 seconds.\n",
      "You can set `force_col_wise=true` to remove the overhead.\n",
      "[LightGBM] [Info] Total Bins 2418\n",
      "[LightGBM] [Info] Number of data points in the train set: 12096, number of used features: 46\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Auto-choosing col-wise multi-threading, the overhead of testing was 0.002335 seconds.\n",
      "You can set `force_col_wise=true` to remove the overhead.\n",
      "[LightGBM] [Info] Total Bins 2404\n",
      "[LightGBM] [Info] Number of data points in the train set: 15120, number of used features: 46\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n",
      "[LightGBM] [Info] Start training from score -1.945910\n"
     ]
    }
   ],
   "source": [
    "for n, model in enumerate(first_models):\n",
    "    # 由考生填写\n",
    "    model_pipeline = Pipeline(steps=[('Scaler',std_sca),('Estimator',model)])\n",
    "    # 由考生填写\n",
    "    MLA_name = model.__class__.__name__\n",
    "    MLA_compare.loc[row_index,'MLA Name'] = MLA_name\n",
    "    MLA_compare.loc[row_index,'MLA Parameters'] = str(model.get_params())\n",
    "    # 由考生填写\n",
    "    cv_results = cross_validate(estimator=model,X=X,y=y,return_train_score=True)\n",
    "    # 由考生填写\n",
    "    MLA_compare.loc[row_index,'MLA Time'] = cv_results[ 'fit_time' ].mean()\n",
    "    MLA_compare.loc[row_index,'MLA Train Accuracy Mean'] = cv_results['train_score'].mean()\n",
    "    MLA_compare.loc[row_index,'MLA Test Accuracy Mean'] = cv_results['test_score'].mean()\n",
    "    model_pipeline.fit(X,y)\n",
    "    MLA_predict[MLA_name] = model_pipeline.predict(X)\n",
    "    row_index+=1    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "4215772d",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MLA Name</th>\n",
       "      <th>MLA Parameters</th>\n",
       "      <th>MLA Train Accuracy Mean</th>\n",
       "      <th>MLA Test Accuracy Mean</th>\n",
       "      <th>MLA Time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>XGBClassifier</td>\n",
       "      <td>{'objective': 'binary:logistic', 'use_label_en...</td>\n",
       "      <td>0.996362</td>\n",
       "      <td>0.87791</td>\n",
       "      <td>3.290725</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>LGBMClassifier</td>\n",
       "      <td>{'boosting_type': 'gbdt', 'class_weight': None...</td>\n",
       "      <td>0.992378</td>\n",
       "      <td>0.874206</td>\n",
       "      <td>0.78671</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         MLA Name                                     MLA Parameters  \\\n",
       "0   XGBClassifier  {'objective': 'binary:logistic', 'use_label_en...   \n",
       "1  LGBMClassifier  {'boosting_type': 'gbdt', 'class_weight': None...   \n",
       "\n",
       "  MLA Train Accuracy Mean MLA Test Accuracy Mean  MLA Time  \n",
       "0                0.996362                0.87791  3.290725  \n",
       "1                0.992378               0.874206   0.78671  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MLA_compare"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "68e2c9e5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>XGBClassifier</th>\n",
       "      <th>LGBMClassifier</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>11997</th>\n",
       "      <td>11998</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14308</th>\n",
       "      <td>14309</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5169</th>\n",
       "      <td>5170</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3326</th>\n",
       "      <td>3327</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12168</th>\n",
       "      <td>12169</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4115</th>\n",
       "      <td>4116</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7647</th>\n",
       "      <td>7648</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10885</th>\n",
       "      <td>10886</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9247</th>\n",
       "      <td>9248</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13225</th>\n",
       "      <td>13226</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>15120 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          Id  XGBClassifier  LGBMClassifier\n",
       "11997  11998              0               0\n",
       "14308  14309              1               1\n",
       "5169    5170              2               2\n",
       "3326    3327              3               3\n",
       "12168  12169              0               0\n",
       "...      ...            ...             ...\n",
       "4115    4116              0               0\n",
       "7647    7648              0               0\n",
       "10885  10886              2               2\n",
       "9247    9248              1               1\n",
       "13225  13226              6               6\n",
       "\n",
       "[15120 rows x 3 columns]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MLA_predict"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cfb3f07a",
   "metadata": {},
   "source": [
    "4.使用 sort_values对MLA_compare 按照集 MLA Test Accuracy Mean 这-列倒序排列,指定 inplace 为 True 覆盖原本数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "1021dcd2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MLA Name</th>\n",
       "      <th>MLA Parameters</th>\n",
       "      <th>MLA Train Accuracy Mean</th>\n",
       "      <th>MLA Test Accuracy Mean</th>\n",
       "      <th>MLA Time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>XGBClassifier</td>\n",
       "      <td>{'objective': 'binary:logistic', 'use_label_en...</td>\n",
       "      <td>0.996362</td>\n",
       "      <td>0.87791</td>\n",
       "      <td>3.290725</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>LGBMClassifier</td>\n",
       "      <td>{'boosting_type': 'gbdt', 'class_weight': None...</td>\n",
       "      <td>0.992378</td>\n",
       "      <td>0.874206</td>\n",
       "      <td>0.78671</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         MLA Name                                     MLA Parameters  \\\n",
       "0   XGBClassifier  {'objective': 'binary:logistic', 'use_label_en...   \n",
       "1  LGBMClassifier  {'boosting_type': 'gbdt', 'class_weight': None...   \n",
       "\n",
       "  MLA Train Accuracy Mean MLA Test Accuracy Mean  MLA Time  \n",
       "0                0.996362                0.87791  3.290725  \n",
       "1                0.992378               0.874206   0.78671  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 由考生填写\n",
    "MLA_compare.sort_values(by=['MLA Test Accuracy Mean'],ascending=False,inplace=True)\n",
    "# 由考生填写\n",
    "MLA_compare"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "9f68dcb2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int64Index([0], dtype='int64')"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MLA_compare.index[-20:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "9e2d1915",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 5)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MLA_compare.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ce85d9ec",
   "metadata": {},
   "source": [
    "5.删除 MLA compare 后20 位数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "09ebb7d8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MLA Name</th>\n",
       "      <th>MLA Parameters</th>\n",
       "      <th>MLA Train Accuracy Mean</th>\n",
       "      <th>MLA Test Accuracy Mean</th>\n",
       "      <th>MLA Time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>LGBMClassifier</td>\n",
       "      <td>{'boosting_type': 'gbdt', 'class_weight': None...</td>\n",
       "      <td>0.992378</td>\n",
       "      <td>0.874206</td>\n",
       "      <td>0.78671</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         MLA Name                                     MLA Parameters  \\\n",
       "1  LGBMClassifier  {'boosting_type': 'gbdt', 'class_weight': None...   \n",
       "\n",
       "  MLA Train Accuracy Mean MLA Test Accuracy Mean MLA Time  \n",
       "1                0.992378               0.874206  0.78671  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 由考生填写\n",
    "MLA_compare.drop(axis=0,index=MLA_compare.index[-20:-1])\n",
    "# 由考生填写"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
